home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Games / Stella Obscura 1.1 / source / Parts ƒ / Initialize.p < prev    next >
Encoding:
Text File  |  1990-05-13  |  6.9 KB  |  239 lines  |  [TEXT/PJMM]

  1. unit Initialize;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Sound, SomeGlobals, Utilities;
  7.  
  8.     const
  9.         objectPictID = 2001;
  10.  
  11.     var
  12.         AppleMenu: MenuHandle;
  13.  
  14.     procedure Init_My_Menus;
  15.     function NewBitMap (var theBitMap: BitMap; theRect: Rect): Ptr;
  16.     procedure InitVariables;
  17.  
  18. implementation
  19.  
  20.     procedure Init_My_Menus;                {Initialize the menus}
  21.         var
  22.             tempMenu: MenuHandle;                  {Throw away all other menu handles}
  23.  
  24.     begin                                   {Start of Init_My_Menus}
  25.         ClearMenuBar;                         {Clear any old menu bars}
  26.         tempMenu := GetMenu(AppleM);
  27.         AddResMenu(tempMenu, 'DRVR');
  28.         InsertMenu(tempMenu, 0);
  29.         AppleMenu := tempMenu;
  30.         tempMenu := GetMenu(GameM);
  31.         InsertMenu(tempMenu, 0);
  32.         tempMenu := GetMenu(OptionsM);
  33.         InsertMenu(tempMenu, 0);
  34.  
  35.         DisableItem(GetMenu(GameM), 2);
  36.         DisableItem(GetMenu(GameM), 3);
  37.  
  38.         DrawMenuBar;
  39.     end;
  40.  
  41. {=================================}
  42.  
  43.     function NewBitMap;
  44.     begin
  45.         with theBitMap, theRect do
  46.             begin
  47.                 rowBytes := ((right - left + 15) div 16) * 2;
  48.                 baseAddr := NewPtr(rowBytes * (bottom - top));
  49.                 bounds := theRect;
  50.                 if MemError <> noErr then
  51.                     begin
  52.                         NewBitMap := nil
  53.                     end
  54.                 else
  55.                     NewBitMap := baseAddr;
  56.             end;
  57.     end;
  58.  
  59. {=================================}
  60.  
  61.     procedure InitVariables;
  62.         var
  63.             index: Integer;
  64.             rawPointer: Ptr;
  65.             Pic_Handle: PicHandle;
  66.             tempRect: Rect;
  67.             theSnd: Handle;
  68.     begin
  69.         rawPointer := NewPtr(SizeOf(GrafPort));    {Initialize and setup offscreen}
  70.         offLeftPort := GrafPtr(rawPointer);
  71.         OpenPort(offLeftPort);
  72.         SetRect(offLeftArea, 0, 0, 127, 241);
  73.         offLeftBits := NewBitMap(offLeftMap, offLeftArea);
  74.         SetPortBits(offLeftMap);
  75.         EraseRect(offLeftMap.bounds);
  76.         ClipRect(offLeftArea);
  77.  
  78.         rawPointer := NewPtr(SizeOf(GrafPort));    {Initialize and setup offscreen}
  79.         offRightPort := GrafPtr(rawPointer);
  80.         OpenPort(offRightPort);
  81.         SetRect(offRightArea, 0, 0, 127, 241);
  82.         offRightBits := NewBitMap(offRightMap, offRightArea);
  83.         SetPortBits(offRightMap);
  84.         EraseRect(offRightMap.bounds);
  85.         ClipRect(offRightArea);
  86.  
  87.         rawPointer := NewPtr(SizeOf(GrafPort));    {Initialize and setup offscreen}
  88.         offLeftVirginPort := GrafPtr(rawPointer);
  89.         OpenPort(offLeftVirginPort);
  90.         SetRect(offLeftVirginArea, 0, 0, 127, 241);
  91.         offLeftVirginBits := NewBitMap(offLeftVirginMap, offLeftVirginArea);
  92.         SetPortBits(offLeftVirginMap);
  93.         EraseRect(offLeftVirginMap.bounds);
  94.         ClipRect(offLeftVirginArea);
  95.  
  96.         rawPointer := NewPtr(SizeOf(GrafPort));    {Initialize and setup offscreen}
  97.         offRightVirginPort := GrafPtr(rawPointer);
  98.         OpenPort(offRightVirginPort);
  99.         SetRect(offRightVirginArea, 0, 0, 127, 241);
  100.         offRightVirginBits := NewBitMap(offRightVirginMap, offRightVirginArea);
  101.         SetPortBits(offRightVirginMap);
  102.         EraseRect(offRightVirginMap.bounds);
  103.         ClipRect(offRightVirginArea);
  104.  
  105.         rawPointer := NewPtr(SizeOf(GrafPort));    {Initialize and setup offscreen}
  106.         offPlayerPort := GrafPtr(rawPointer);
  107.         OpenPort(offPlayerPort);
  108.         SetRect(offPlayerArea, 0, 0, 512, 322);
  109.         offPlayerBits := NewBitMap(offPlayerMap, offPlayerArea);
  110.         SetPortBits(offPlayerMap);
  111.         EraseRect(offPlayerMap.bounds);
  112.         SetPort(offPlayerPort);
  113.         Pic_Handle := GetPicture(objectPictID);
  114.         SetRect(tempRect, 0, 0, 512, 322);
  115.         if (Pic_Handle <> nil) then
  116.             begin
  117.                 ClipRect(tempRect);
  118.                 HLock(Handle(Pic_Handle));
  119.                 tempRect.Right := tempRect.Left + (Pic_Handle^^.picFrame.Right - Pic_Handle^^.picFrame.Left);
  120.                 tempRect.Bottom := tempRect.Top + (Pic_Handle^^.picFrame.Bottom - Pic_Handle^^.picFrame.Top);
  121.                 HUnLock(Handle(Pic_Handle));
  122.             end;
  123.         if (Pic_Handle <> nil) then
  124.             DrawPicture(Pic_Handle, tempRect);
  125.         ReleaseResource(Handle(Pic_Handle));
  126.         SetRect(tempRect, 0, 0, 1023, 1023);
  127.         ClipRect(tempRect);
  128.  
  129.         if forgetSound then
  130.             soundOn := FALSE
  131.         else
  132.             soundOn := TRUE;
  133.         slowOn := FALSE;
  134.         playing := FALSE;
  135.         pausing := FALSE;
  136.         chanPtr := nil;
  137.         GetDateTime(RandSeed);
  138.  
  139.         playMask := EveryEvent - MDownMask - MUpMask - KeyUpMask - AutoKeyMask - UpdateMask - ActivMask;
  140.         idleMask := EveryEvent - KeyUpMask - AutoKeyMask;
  141.  
  142.         for index := 1 to 36 do
  143.             begin
  144.                 heightRatio[index] := ABS(SIN(((index - 1) * 10) * (6.28318 / 360)));
  145.             end;
  146.  
  147.         SetRect(bckgrndSrc, 0, 0, 254, 241);
  148.         bckgrndDst := bckgrndSrc;
  149.         OffsetRect(bckgrndDst, 129, 50);
  150.         SetRect(leftBckgrndDst, 0, 0, 127, 241);
  151.         rightBckgrndDst := leftBckgrndDst;
  152.         smallBckGrndSrc := leftBckgrndDst;
  153.         OffsetRect(leftBckgrndDst, 129, 50);
  154.         OffsetRect(rightBckgrndDst, 256, 50);
  155.  
  156.         leftScreenRgn := NewRgn;
  157.         MoveTo(129, 50);
  158.         OpenRgn;
  159.         Line(127, 0);
  160.         Line(0, 241);
  161.         Line(-127, 0);
  162.         Line(0, -241);
  163.         CloseRgn(leftScreenRgn);
  164.         MoveHHi(Handle(leftScreenRgn));
  165.         HLock(Handle(leftScreenRgn));
  166.  
  167.         rightScreenRgn := NewRgn;
  168.         MoveTo(256, 50);
  169.         OpenRgn;
  170.         Line(127, 0);
  171.         Line(0, 241);
  172.         Line(-127, 0);
  173.         Line(0, -241);
  174.         CloseRgn(rightScreenRgn);
  175.         MoveHHi(Handle(rightScreenRgn));
  176.         HLock(Handle(rightScreenRgn));
  177.  
  178.         SetRect(bigClip, -1000, -1000, 1512, 1342);
  179.  
  180.         SetRect(shieldSrc, 20, 14, 40, 24);
  181.         leftShieldDst := shieldSrc;
  182.         OffsetRect(leftShieldDst, 129, 50);
  183.         rightShieldDst := shieldSrc;
  184.         OffsetRect(rightShieldDst, 256, 50);
  185.  
  186.         SetRect(crossHairSrc[0], 442, 1, 453, 12);
  187.         SetRect(crossHairMask[0], 430, 1, 441, 12);
  188.         SetRect(crossHairSrc[2], 492, 1, 503, 12);
  189.         SetRect(crossHairMask[2], 456, 1, 467, 12);
  190.         SetRect(crossHairSrc[1], 492, 1, 503, 12);
  191.         SetRect(crossHairMask[1], 468, 1, 479, 12);
  192.  
  193.         SetRect(shipSrc[0], 256, 1, 291, 24);
  194.         SetRect(shipSrc[1], 256, 25, 291, 48);
  195.         SetRect(shipSrc[2], 256, 49, 291, 72);
  196.         SetRect(shipSrc[3], 256, 73, 291, 96);
  197.         SetRect(shipSrc[4], 256, 97, 291, 120);
  198.  
  199.         SetRect(shipMaskSrc[0], 292, 1, 327, 24);
  200.         SetRect(shipMaskSrc[1], 292, 25, 327, 48);
  201.         SetRect(shipMaskSrc[2], 292, 49, 327, 72);
  202.         SetRect(shipMaskSrc[3], 292, 73, 327, 96);
  203.         SetRect(shipMaskSrc[4], 292, 97, 327, 120);
  204.  
  205.         SetRect(enemySrc[0], 453, 26, 481, 58);
  206.         SetRect(enemySrc[1], 453, 59, 481, 91);
  207.         SetRect(enemySrc[2], 453, 92, 481, 124);
  208.         SetRect(enemySrc[3], 453, 125, 481, 157);
  209.         SetRect(enemySrc[4], 453, 158, 481, 190);
  210.         SetRect(enemySrc[5], 453, 191, 481, 223);
  211.         SetRect(enemySrc[6], 453, 224, 481, 256);
  212.         SetRect(enemySrc[7], 453, 257, 481, 289);
  213.         SetRect(enemySrc[8], 453, 290, 481, 322);
  214.  
  215.         SetRect(enemyMaskSrc[0], 484, 26, 512, 58);
  216.         SetRect(enemyMaskSrc[1], 484, 59, 512, 91);
  217.         SetRect(enemyMaskSrc[2], 484, 92, 512, 124);
  218.         SetRect(enemyMaskSrc[3], 484, 125, 512, 157);
  219.         SetRect(enemyMaskSrc[4], 484, 158, 512, 190);
  220.         SetRect(enemyMaskSrc[5], 484, 191, 512, 223);
  221.         SetRect(enemyMaskSrc[6], 484, 224, 512, 256);
  222.         SetRect(enemyMaskSrc[7], 484, 257, 512, 289);
  223.         SetRect(enemyMaskSrc[8], 484, 290, 512, 322);
  224.  
  225.         theSnd := GetNamedResource('snd ', 'laserFire');
  226.         MoveHHi(theSnd);
  227.         theSnd := GetNamedResource('snd ', 'enemyFire');
  228.         MoveHHi(theSnd);
  229.         theSnd := GetNamedResource('snd ', 'hyperSpace');
  230.         MoveHHi(theSnd);
  231.         theSnd := GetNamedResource('snd ', 'enemyBoom');
  232.         MoveHHi(theSnd);
  233.         theSnd := GetNamedResource('snd ', 'enterHole');
  234.         MoveHHi(theSnd);
  235.     end;
  236.  
  237. {=================================}
  238.  
  239. end.